package com.sztx.pay.center.core.service.impl;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sztx.pay.center.common.util.Constance;
import com.sztx.pay.center.common.util.CurrencyUtil;
import com.sztx.pay.center.common.yhbf.YHBFSensitiveEnc;
import com.sztx.pay.center.common.yhbf.YHBFUtil;
import com.sztx.pay.center.core.service.OrderQueryService;
import com.sztx.pay.center.core.service.bean.rpc.OrderB2CDump;
import com.sztx.pay.center.core.service.bean.rpc.OrderCallback;
import com.sztx.pay.center.core.service.bean.rpc.OrderRechargeDump;
import com.sztx.pay.center.core.service.bean.rpc.OrderRefundDump;
import com.sztx.pay.center.core.service.bean.rpc.OrderSettle;
import com.sztx.pay.center.core.service.bean.rpc.OrderTransferDump;
import com.sztx.pay.center.core.service.bean.rpc.OrderWithdrawDump;
import com.sztx.pay.center.core.service.bean.rpc.PayFlow;
import com.sztx.pay.center.core.service.bean.rpc.UserActFlow;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderB2cMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderRechargeMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderRefundMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderTransferMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderWithdrawMysqlDAO;
import com.sztx.pay.center.dataaccess.domain.CallbackNotifyDO;
import com.sztx.pay.center.dataaccess.domain.OrderB2cDO;
import com.sztx.pay.center.dataaccess.domain.OrderB2cDumpDO;
import com.sztx.pay.center.dataaccess.domain.OrderRechargeDO;
import com.sztx.pay.center.dataaccess.domain.OrderRechargeDumpDO;
import com.sztx.pay.center.dataaccess.domain.OrderRefundDO;
import com.sztx.pay.center.dataaccess.domain.OrderRefundDumpDO;
import com.sztx.pay.center.dataaccess.domain.OrderTransferDO;
import com.sztx.pay.center.dataaccess.domain.OrderTransferDumpDO;
import com.sztx.pay.center.dataaccess.domain.OrderWithdrawDO;
import com.sztx.pay.center.dataaccess.domain.OrderWithdrawDumpDO;
import com.sztx.pay.center.dataaccess.domain.PayFlowDO;
import com.sztx.pay.center.dataaccess.domain.SettleOrderDO;
import com.sztx.pay.center.dataaccess.domain.UserActFlowDO;
import com.sztx.se.common.util.StringUtil;

/**
 * @author Hinsteny
 * @date 2016/10/26
 * @copyright: 2016 All rights reserved.
 */
@Service
public class OrderQueryServiceImpl implements OrderQueryService {

	private static final Logger logger = LoggerFactory.getLogger(OrderQueryServiceImpl.class);
	
	@Autowired
	private OrderB2cMysqlDAO orderB2cMysqlDAO;
	
	@Autowired
	private OrderRechargeMysqlDAO orderRechargeMysqlDAO;
	
	@Autowired
	private OrderRefundMysqlDAO orderRefundMysqlDAO;
	
	@Autowired
	private OrderTransferMysqlDAO orderTransferMysqlDAO;
	
	@Autowired
	private OrderWithdrawMysqlDAO orderWithdrawMysqlDAO;

	@Override
	public List<OrderB2CDump> findB2C(Integer taskItemNum, List<String> taskItems, Integer fetchNum, String startTime, String endTime) {
		List<OrderB2cDumpDO> schedules = orderB2cMysqlDAO.findUnHandleForSchedule(taskItemNum, taskItems, fetchNum, startTime, endTime);
		List<OrderB2CDump> result = null;
		if(schedules != null && schedules.size() > 0){
			result = new ArrayList<OrderB2CDump>(schedules.size());
			OrderB2CDump dump = null;
			for(OrderB2cDumpDO item : schedules){
				dump = new OrderB2CDump();
				dump = renderOrderB2C(item);
				dump.setPayFlows(renderPayFlowDOList(item.getPayFlows()));
				dump.setOrderCallbacks(renderCallbackNotifyDOList(item.getOrderCallbacks()));
				dump.setUserActFlows(renderUserActFlowDOList(item.getUserActFlows()));
				dump.setSettleOrders(renderSettleOrderDOList(item.getSettleOrders()));
				result.add(dump);
			}
		}
		return result;
	}

	@Override
	public List<OrderRechargeDump> findRecharge(Integer taskItemNum, List<String> taskItems, Integer fetchNum, String startTime, String endTime) {
		List<OrderRechargeDumpDO> schedules = orderRechargeMysqlDAO.findUnHandleForSchedule(taskItemNum, taskItems, fetchNum, startTime, endTime);
		List<OrderRechargeDump> result = null;
		if(schedules != null && schedules.size() > 0){
			result = new ArrayList<OrderRechargeDump>(schedules.size());
			OrderRechargeDump dump = null;
			for(OrderRechargeDumpDO item : schedules){
				dump = new OrderRechargeDump();
				dump = renderOrderRecharge(item);
				dump.setPayFlows(renderPayFlowDOList(item.getPayFlows()));
				dump.setOrderCallbacks(renderCallbackNotifyDOList(item.getOrderCallbacks()));
				dump.setUserActFlows(renderUserActFlowDOList(item.getUserActFlows()));
				result.add(dump);
			}
		}
		return result;
	}

	@Override
	public List<OrderRefundDump> findRefund(Integer taskItemNum, List<String> taskItems, Integer fetchNum, String startTime, String endTime) {
		List<OrderRefundDumpDO> schedules = orderRefundMysqlDAO.findUnHandleForSchedule(taskItemNum, taskItems, fetchNum, startTime, endTime);
		List<OrderRefundDump> result = null;
		if(schedules != null && schedules.size() > 0){
			result = new ArrayList<OrderRefundDump>(schedules.size());
			OrderRefundDump dump = null;
			for(OrderRefundDumpDO item : schedules){
				dump = new OrderRefundDump();
				dump = renderOrderRefund(item);
				dump.setPayFlows(renderPayFlowDOList(item.getPayFlows()));
				dump.setOrderCallbacks(renderCallbackNotifyDOList(item.getOrderCallbacks()));
				dump.setUserActFlows(renderUserActFlowDOList(item.getUserActFlows()));
				result.add(dump);
			}
		}
		return result;
	}

	@Override
	public List<OrderTransferDump> findTransfer(Integer taskItemNum, List<String> taskItems, Integer fetchNum, String startTime, String endTime) {
		List<OrderTransferDumpDO> schedules = orderTransferMysqlDAO.findUnHandleForSchedule(taskItemNum, taskItems, fetchNum, startTime, endTime);
		List<OrderTransferDump> result = null;
		if(schedules != null && schedules.size() > 0){
			result = new ArrayList<OrderTransferDump>(schedules.size());
			OrderTransferDump dump = null;
			for(OrderTransferDumpDO item : schedules){
				dump = new OrderTransferDump();
				dump = renderOrderTransfer(item);
				dump.setPayFlows(renderPayFlowDOList(item.getPayFlows()));
				dump.setOrderCallbacks(renderCallbackNotifyDOList(item.getOrderCallbacks()));
				dump.setUserActFlows(renderUserActFlowDOList(item.getUserActFlows()));
				result.add(dump);
			}
		}
		return result;
	}

	@Override
	public List<OrderWithdrawDump> findWithdraw(Integer taskItemNum, List<String> taskItems, Integer fetchNum, String startTime, String endTime) {
		List<OrderWithdrawDumpDO> schedules = orderWithdrawMysqlDAO.findUnHandleForSchedule(taskItemNum, taskItems, fetchNum, startTime, endTime);
		List<OrderWithdrawDump> result = null;
		if(schedules != null && schedules.size() > 0){
			result = new ArrayList<OrderWithdrawDump>(schedules.size());
			OrderWithdrawDump dump = null;
			for(OrderWithdrawDumpDO item : schedules){
				dump = new OrderWithdrawDump();
				dump = renderOrderWithdraw(item);
				dump.setPayFlows(renderPayFlowDOList(item.getPayFlows()));
				dump.setOrderCallbacks(renderCallbackNotifyDOList(item.getOrderCallbacks()));
				dump.setUserActFlows(renderUserActFlowDOList(item.getUserActFlows()));
				result.add(dump);
			}
		}
		return result;
	}
	
	private List<PayFlow> renderPayFlowDOList(List<PayFlowDO> list){
		List<PayFlow> result = null;
		if(list != null && list.size() > 0){
			result = new ArrayList<PayFlow>(list.size());
			PayFlow dump = null;
			for(PayFlowDO item : list){
				dump = new PayFlow();
				dump = renderPayFlow(item);
				result.add(dump);
			}
		}
		return result;
	}
	
	private List<OrderCallback> renderCallbackNotifyDOList(List<CallbackNotifyDO> list){
		List<OrderCallback> result = null;
		if(list != null && list.size() > 0){
			result = new ArrayList<OrderCallback>(list.size());
			OrderCallback dump = null;
			for(CallbackNotifyDO item : list){
				dump = new OrderCallback();
				dump = renderOrderCallback(item);
				result.add(dump);
			}
		}
		return result;
	}
	
	private List<UserActFlow> renderUserActFlowDOList(List<UserActFlowDO> list){
		List<UserActFlow> result = null;
		if(list != null && list.size() > 0){
			result = new ArrayList<UserActFlow>(list.size());
			UserActFlow dump = null;
			for(UserActFlowDO item : list){
				dump = new UserActFlow();
				dump = renderAccountFlow(item);
				result.add(dump);
			}
		}
		return result;
	}
	
	private List<OrderSettle> renderSettleOrderDOList(List<SettleOrderDO> list){
		List<OrderSettle> result = null;
		if(list != null && list.size() > 0){
			result = new ArrayList<OrderSettle>(list.size());
			OrderSettle dump = null;
			for(SettleOrderDO item : list){
				dump = new OrderSettle();
				dump = renderOrderSettle(item);
				result.add(dump);
			}
		}
		return result;
	}
	
	
	/*====================== 实体转换 ==========================*/
	private static final String DEFAULTTYPE = "未知";
	
	private OrderB2CDump renderOrderB2C(OrderB2cDO order){
		if(order == null) return null;
		OrderB2CDump result = new OrderB2CDump();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		result.setGuaranteeTypeStr(getB2CGuaranteeTypeStr(order.getGuaranteeType()));
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getOrderType() == null ? -1:order.getOrderType());
		result.setOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		Constance.B2COrderState b2cOrderState = Constance.B2COrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setOrderStatusStr(b2cOrderState == null ? DEFAULTTYPE : b2cOrderState.getDesc());
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		result.setChannelTypeStr(getB2COrderChannelStr(order.getOrderChannel()));
//		Constance.PayType payType = Constance.PayType.valueOf(order.getPayType() == null ? -1:order.getPayType());
//		result.setPayTypeStr(payType == null ? getpayTypeByBankId(order.getPayBankId()) : payType.getDesc());
		result.setPayTypeStr(getpayTypeByBankId(order.getPayBankId()));
		result.setOrderChannelStr(getB2COrderChannelStr(order.getOrderChannel()));
		result.setProductTypeStr(getB2CProductTypeStr(order.getProductType()));
		
		result.setTradeAmount(CurrencyUtil.fen2yuan(order.getTradeAmount()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setFee(CurrencyUtil.fen2yuan(order.getFee()));
		return result;
	}
	
	private OrderRechargeDump renderOrderRecharge(OrderRechargeDO order){
		if(order == null) return null;
		OrderRechargeDump result = new OrderRechargeDump();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.ChargeOrderState rechargeStatus = Constance.ChargeOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setRechargeStatusStr(rechargeStatus == null ? DEFAULTTYPE : rechargeStatus.getDesc());
//		Constance.PayType payType = Constance.PayType.valueOf(order.getPayType() == null ? -1:order.getPayType());
//		result.setPayTypeStr(payType == null ?  getpayTypeByBankId(order.getPayBankId()) : payType.getDesc());
		result.setPayTypeStr(getpayTypeByBankId(order.getPayBankId()));
		result.setRechargeChannelStr(getRECRechargeChannelStr(order.getRechargeChannel() == null ? -1:order.getRechargeChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		Constance.CardActType bankCardActType = Constance.CardActType.valueOf(order.getBankCardActType() == null ? -1 : order.getBankCardActType());
		result.setBankCardActType(bankCardActType == null ? DEFAULTTYPE : bankCardActType.getDesc());
		Constance.CardType bankCardType = Constance.CardType.valueOf(order.getBankCardType() == null ? -1 : order.getBankCardType());
		result.setBankCardType(bankCardType == null ? DEFAULTTYPE : bankCardType.getDesc());
		
		result.setRechargeAmount(CurrencyUtil.fen2yuan(order.getRechargeAmount()));
		result.setRechargeFee(CurrencyUtil.fen2yuan(order.getRechargeFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));

		result.setBankCardNo(YHBFSensitiveEnc.sensitiveDec(order.getBankCardNo(), "cardno"));
		return result;
	}
	
	private OrderRefundDump renderOrderRefund(OrderRefundDO order){
		if(order == null) return null;
		OrderRefundDump result = new OrderRefundDump();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.RefundType refundType = Constance.RefundType.valueOf(order.getRefundType() == null ? -1:order.getRefundType());
		result.setRefundTypeStr(refundType == null ? DEFAULTTYPE : refundType.getDesc());
		Constance.RefundOrderState refundStatus = Constance.RefundOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setRefundStatusStr(refundStatus == null ? DEFAULTTYPE : refundStatus.getDesc());
		result.setRefundChannelStr(getRECRechargeChannelStr(order.getRefundChannel() == null ? -1:order.getRefundChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));

		result.setRefundAmount(CurrencyUtil.fen2yuan(order.getRefundAmount()));
		result.setRefundFee(CurrencyUtil.fen2yuan(order.getRefundFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		return result;
	}
	
	private OrderTransferDump renderOrderTransfer(OrderTransferDO order){
		if(order == null) return null;
		OrderTransferDump result = new OrderTransferDump();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.TransferType transferType = Constance.TransferType.valueOf(order.getTransferType() == null ? -1:order.getTransferType());
		result.setTransferTypeStr(transferType == null ? DEFAULTTYPE : transferType.getDesc());
		Constance.TransferOrderState transferStatus = Constance.TransferOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setTransferStatusStr(transferStatus == null ? DEFAULTTYPE : transferStatus.getDesc());
		result.setTransferChannelStr(getRECRechargeChannelStr(order.getTransferChannel() == null ? -1:order.getTransferChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		Constance.CardActType cardactType = Constance.CardActType.valueOf(order.getPayeeCardActType() == null ? -1:order.getPayeeCardActType());
		result.setCardactTypeStr(cardactType == null ? DEFAULTTYPE : cardactType.getDesc());
		Constance.BaseBusinessStatus busniessStatus = Constance.BaseBusinessStatus.valueOf(order.getBusniessStatus());
		result.setBusniessStatusStr(busniessStatus == null ? DEFAULTTYPE : busniessStatus.getDesc());
		Constance.TradeIfUserPwd ifUserPwd = Constance.TradeIfUserPwd.valueOf(order.getIsUsePwd());
		result.setIsUsePwdStr(ifUserPwd == null ? DEFAULTTYPE : ifUserPwd.getDesc());
		Constance.TransferBusinessID busniessStr = Constance.TransferBusinessID.valueOf(order.getBusniessId());
		result.setBusniessId(busniessStr == null ? DEFAULTTYPE : busniessStr.getDesc());

		result.setTransferAmount(CurrencyUtil.fen2yuan(order.getTransferAmount()));
		result.setTransferFee(CurrencyUtil.fen2yuan(order.getTransferFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		
		result.setCardNo(deCodeMessage(order.getPayeeCardNo()));
		return result;
	}
	
	private OrderWithdrawDump renderOrderWithdraw(OrderWithdrawDO order){
		if(order == null) return null;
		OrderWithdrawDump result = new OrderWithdrawDump();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.WithDrawType withdrawType = Constance.WithDrawType.valueOf(order.getWithdrawType() == null ? -1:order.getWithdrawType());
		result.setWithdrawTypeStr(withdrawType == null ? DEFAULTTYPE : withdrawType.getDesc());
		Constance.WithdrawState withdrawStatus = Constance.WithdrawState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setWithdrawStatusStr(withdrawStatus == null ? DEFAULTTYPE : withdrawStatus.getDesc());
		result.setWithdrawChannelStr(getRECRechargeChannelStr(order.getWithdrawChannel() == null ? -1:order.getWithdrawChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		result.setVerifyTypeStr(getWDVerifyTypeStr(order.getVerifyType() == null ? -1:order.getVerifyType()));
		Constance.BaseBusinessStatus busniessStatus = Constance.BaseBusinessStatus.valueOf(order.getBusniessStatus());
		result.setBusniessStatusStr(busniessStatus == null ? DEFAULTTYPE : busniessStatus.getDesc());
		Constance.WithdrawWay withdrawWay = Constance.WithdrawWay.valueOf(order.getWithdrawWay() == null ? -1:Integer.parseInt(order.getWithdrawWay()));
		result.setWithdrawWay(withdrawWay == null ? DEFAULTTYPE : withdrawWay.getDesc());

		result.setWithdrawAmount(CurrencyUtil.fen2yuan(order.getWithdrawAmount()));
		result.setWithdrawFee(CurrencyUtil.fen2yuan(order.getWithdrawFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		logger.info("Order WithdrawCardNo is {}", order.getWithdrawCardNo());
		result.setWithdrawCardNo(YHBFSensitiveEnc.sensitiveDec(order.getWithdrawCardNo(), "cardno"));
		return result;
	}
	
	private PayFlow renderPayFlow(PayFlowDO order){
		if(order == null) return null;
		PayFlow result = new PayFlow();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.UserType payerUserType = Constance.UserType.valueOf(order.getPayerUserType() == null ? -1:order.getPayerUserType());
		result.setPayerUserTypeStr(payerUserType == null ? DEFAULTTYPE : payerUserType.getDesc());
		Constance.UserActType payerActType = Constance.UserActType.valueOf(order.getPayerActType() == null ? -1:order.getPayerActType());
		result.setPayerActTypeStr(payerActType == null ? DEFAULTTYPE : payerActType.getDesc());
		Constance.CardType payerCardType = Constance.CardType.valueOf(order.getPayerCardType() == null ? -1:order.getPayerCardType());
		result.setPayerCardTypeStr(payerCardType == null ? DEFAULTTYPE : payerCardType.getDesc());
		result.setPayerCardActTypeStr(getPayFlowPayerCardActTypeStr(order.getPayerCardActType() == null ? -1:order.getPayerCardActType()));
		Constance.IdCardType identityType = Constance.IdCardType.valueOf(order.getPayerIdentityType() == null ? -1:order.getPayerIdentityType());
		result.setPayerIdentityTypeStr(identityType == null ? DEFAULTTYPE : identityType.getDesc());
		Constance.UserType payeeUserType = Constance.UserType.valueOf(order.getPayeeUserType() == null ? -1:order.getPayeeUserType());
		result.setPayeeUserTypeStr(payeeUserType == null ? DEFAULTTYPE : payeeUserType.getDesc());
		Constance.UserActType payeeActType = Constance.UserActType.valueOf(order.getPayeeActType() == null ? -1:order.getPayeeActType());
		result.setPayeeActTypeStr(payeeActType == null ? DEFAULTTYPE : payeeActType.getDesc());
		result.setPayeeCardActTypeStr(getPayFlowPayerCardActTypeStr(order.getPayerActType() == null ? -1:order.getPayerActType()));
		Constance.PayFlowType payType = Constance.PayFlowType.valueOf(order.getPayType() == null ? -1:order.getPayType());
		result.setPayTypeStr(payType == null ? DEFAULTTYPE : payType.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getTradeOrderType() == null ? -1:order.getTradeOrderType());
		result.setTradeOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		Constance.PayFlowState payStatus = Constance.PayFlowState.valueOf(order.getPayStatus() == null ? -1:order.getPayStatus());
		result.setPayStatusStr(payStatus == null ? DEFAULTTYPE : payStatus.getDesc());
		result.setHandleStatusStr(getPayFlowHandleStatusStr(order.getHandleStatus()));
		
		result.setAmount(CurrencyUtil.fen2yuan(order.getAmount()));
		
		result.setPayerBankAct(deCodeMessage(order.getPayerBankAct()));
		result.setPayerIdentityNo(deCodeMessage(order.getPayerIdentityNo()));
		result.setPayerMobile(deCodeMessage(order.getPayerMobile()));
		result.setPayeeBankAct(deCodeMessage(order.getPayeeBankAct()));
		result.setPayeeActNo(YHBFSensitiveEnc.sensitiveDec(order.getPayeeActNo(), "cardno"));
		return result;
	}

	private OrderCallback renderOrderCallback(CallbackNotifyDO order){
		if(order ==null) return null;
		OrderCallback result = new OrderCallback();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.NotifyState status = Constance.NotifyState.valueOf(order.getStatus() == null ? -1:order.getStatus());
		result.setStatusStr(status == null ? DEFAULTTYPE : status.getDesc());
		Constance.CallBackOrderState orderStatus = Constance.CallBackOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setOrderStatusStr(orderStatus == null ? DEFAULTTYPE : orderStatus.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getOrderType() == null ? -1:order.getOrderType());
		result.setOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		
		result.setTotalFee(CurrencyUtil.fen2yuan(order.getTotalFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		return result;
	}

	private OrderSettle renderOrderSettle(SettleOrderDO order){
		if(order ==null) return null;
		OrderSettle result = new OrderSettle();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.OrderSettleType settleType = Constance.OrderSettleType.valueOf(order.getSettleType());
		result.setSettleTypeStr(settleType == null ? DEFAULTTYPE : settleType.getDesc());
		Constance.OrderSettleState state = Constance.OrderSettleState.valueOf(order.getState());
		result.setStateStr(state == null ? DEFAULTTYPE : state.getDesc());
		
		result.setSettleAmount(CurrencyUtil.fen2yuan(order.getSettleAmount()));
		result.setHandlingFee(CurrencyUtil.fen2yuan(order.getHandlingFee()));
		result.setFundsToAccount(CurrencyUtil.fen2yuan(order.getFundsToAccount()));
		return result;
	}

	private UserActFlow renderAccountFlow(UserActFlowDO order){
		if(order ==null) return null;
		UserActFlow result = new UserActFlow();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.UserActType actType = Constance.UserActType.valueOf(order.getActType() == null ? -1:order.getActType());
		result.setActTypeStr(actType == null ? DEFAULTTYPE : actType.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getTradeType()== null ? -1:order.getTradeType());
		result.setTradeTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		
		result.setActBalance(CurrencyUtil.fen2yuan(order.getActBalance()));
		result.setTranAmount(CurrencyUtil.fen2yuan(order.getTranAmount()));
		return result;
	}

	/*====================== /实体转换 ==========================*/

	/*====================== 一些小方法 ==========================*/
	private String getB2CGuaranteeTypeStr(Integer guaranteeType){
		if(guaranteeType == 0)
			return "及时";
		else if(guaranteeType == 1)
			return "担保";
		else
			return DEFAULTTYPE;
	}
	private String getInnerStatusStr(Integer innerStatus){
		if(innerStatus == 0)
			return "正常";
		else if(innerStatus == 1)
			return "作废";
		else
			return DEFAULTTYPE;
	}
	private String getB2COrderChannelStr(Integer orderChannel){
		if(orderChannel == 1)
			return "网站";
		else if(orderChannel == 2)
			return "手机";
		else if(orderChannel == 3)
			return "微信";
		else
			return DEFAULTTYPE;
	}
	private String getB2CProductTypeStr(Integer productType){
		if(productType == 1)
			return "实物";
		else if(productType == 2)
			return "虚拟";
		else
			return DEFAULTTYPE;
	}
	private String getRECRechargeChannelStr(Byte rechargeChannel){
		if(rechargeChannel == 1)
			return "网站";
		else if(rechargeChannel == 2)
			return "手机";
		else if(rechargeChannel == 3)
			return "微信";
		else if(rechargeChannel == 4)
			return "内部";
		else
			return DEFAULTTYPE;
	}
	private String getWDVerifyTypeStr(Byte verifyType){
		if(verifyType == 0)
			return "无需审批";
		else if(verifyType == 1)
			return "需要审批";
		else
			return DEFAULTTYPE;
	}
	private String getPayFlowHandleStatusStr(int handleStatus){
		if(handleStatus == 0)
			return "未处理";
		else if(handleStatus == 1)
			return "已处理";
		else
			return DEFAULTTYPE;
	}
	private String getPayFlowPayerCardActTypeStr(Integer payerActType){
		if(payerActType == 1)
			return "对私账户";
		else if(payerActType == 2)
			return "对公账户";
		else
			return DEFAULTTYPE;
	}
	private String getpayTypeByBankId(String bankId){
		if(StringUtil.isBlank(bankId)) return DEFAULTTYPE;
		if(bankId.startsWith("0"))
			return "余额支付";
		else if(bankId.startsWith("1"))
			return "网银支付";
		else if(bankId.startsWith("2"))
			return "快捷支付";
		else if(bankId.startsWith("3")){
			if(("3000000").equals(bankId))
				return "支付宝WAP支付";
			else if(("3000001").equals(bankId))
				return "微信公众号支付";
			else if(("3000002").equals(bankId))
				return "微信APP支付";
			else  if(("3000003").equals(bankId))
				return "微信APP支付(ios)";
			else  if(("3000004").equals(bankId))
				return "支付宝扫码";
			else  if(("3000005").equals(bankId))
				return "微信扫码";
			else 
				return DEFAULTTYPE;
		} else if(bankId.startsWith("4"))
			return "转帐支付类型";
		else if(bankId.startsWith("5"))
			return "提现";
		else if(bankId.startsWith("6"))
			return "代发到银行";
		else if(bankId.startsWith("7"))
			return "代发到第三方支付账户";
		else
			return DEFAULTTYPE;
	}

	// 提现的实体里有部分加密字段在此解密 
	private String deCodeMessage(String message){
		if(StringUtil.isNotBlank(message)){
			try {
				return YHBFUtil.decrypt(message);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return message;
	}

	/*====================== /一些小方法  ==========================*/

}
